// @Author EthanScriptOn
// @Desc
package log_dispatcher

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_basic_components/queue"
	log2 "gitee.com/fatzeng/srf_switch_log/log"
	"gitee.com/fatzeng/srf_switch_log/log_task"
	"gitee.com/fatzeng/srf_switch_protocol/protocol/log"
)

type LoggerFormatForward struct {
	*queue.ForwardQueue
}

func GenerateLoggerFormatForward() *LoggerFormatForward {
	return &LoggerFormatForward{
		ForwardQueue: queue.GenerateForwardQueue(),
	}
}

func (l *LoggerFormatForward) Push(task interface{}) {
	unitTask, ok := task.(*log_task.LogUnitTask)
	if !ok {
		log.Logger().Error(fmt.Errorf("LoggerFormatForward forward task error task is %v", task))
		return
	}
	exportPool, err := log2.GetExporterPool()
	if err != nil {
		log.Logger().Error(fmt.Errorf("LoggerFormatForward get ExporterPool error %v", err))
		return
	}
	if err = exportPool.Submit(unitTask); err != nil {
		log.Logger().Error(fmt.Errorf("LoggerFormatForward forward submit error %v", err))
	}
}
